package org.bigdata.zc.controller;

import lombok.extern.slf4j.Slf4j;
import org.bigdata.zc.mongo.MatchScheduleWin;
import org.bigdata.zc.mongo.repository.MatchScheduleRepository;
import org.bigdata.zc.mongo.repository.MatchScheduleRpt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by Stephen on 2017/11/1.
 */
@RestController
@Slf4j
public class CupController {

    @Autowired
    MatchScheduleRepository matchScheduleRepository;

    @Autowired
    private MatchScheduleRpt matchScheduleRpt;

    /**
     * 默认查询最近一周赛事
     * @param cupId
     * @return
     */
    @RequestMapping(value = "/todayCupMatchList", method = RequestMethod.POST)
    @ResponseBody
    public List<MatchScheduleWin> todayCupMatchList(@RequestParam(value="cupId", required=false) String cupId){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date date = calendar.getTime();
        calendar.add(Calendar.DAY_OF_MONTH, 18);
        Date endDate = calendar.getTime();
        List<MatchScheduleWin> matchScheduleWins = matchScheduleRpt.findMatchScheduleWinByDateTime(cupId,date,endDate);
        return matchScheduleWins;
    }
}
